package Thread.Old.Runable3;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class RunableImpl2 implements Runnable {
        private int num = 100;
        //创建一个锁
        Lock l = new ReentrantLock();
        @Override
        public void run() {
            while(true)
            {
                l.lock();

                //放个锁
                if (num > 0) {
                    try {
                        Thread.sleep(10);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println(Thread.currentThread().getName() + "-->" + num);
                    num--;
                    //用于卖票
                }
                l.unlock();
                //施放锁
            }

        }
}
